//
//  NSObject+AFN.h
//  MCCSframework
//
//  Created by qq on 2019/8/6.
//  Copyright © 2019 yhy. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AFNetworking.h"
#import "APIError.h"

NS_ASSUME_NONNULL_BEGIN
@class RACSignal;

@interface NSObject (AFN)
-(NSURLSessionDataTask*)postUrl:(NSString *)url
                         params:(id)params
                        headers:(NSDictionary<NSString *,NSString*>*)headers
                    requestType:(NSString *)requestType success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                        failure:(void (^)(NSURLSessionDataTask* task, NSError *error))failure;
-(NSURLSessionDataTask*)getUrl:(NSString*)url
                        params:(NSDictionary<NSString *,id>*)params
                       headers:(NSDictionary<NSString *,NSString*>*)headers
                       success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
                       failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;

-(RACSignal*)dictionaryFromUrl:(NSString*)url
                method:(NSString*)method
                 param:(NSDictionary*)param
                 token:(NSString*)token
             errorFilter:(Class<JSONResponseErrorFilter>)validator;
-(RACSignal*)dataFromUrl:(NSString*)url
                  method:(NSString*)method
                  params:(NSDictionary*)params
                   token:(NSString*)token
               errorFilter:(Class<JSONResponseErrorFilter>)errorFilter
               dataClass:(Class)dataClass
              parseBlock:(id (^)(id data,id resp,NSError** error))parseBlock;

// MARK: --- token => headers 
// token 可以放到 headers 中
// 这是针对那些 token 不放在 "token" 字段，或者 header 中需要放入额外字段的接口而设计的
-(RACSignal*)dictionaryFromUrl:(NSString*)url
                        method:(NSString*)method
                         param:(NSDictionary<NSString*,NSString*>*)param
                       headers:(NSDictionary*)headers
                   errorFilter:(Class<JSONResponseErrorFilter>)errorFilter;
-(RACSignal*)dataFromUrl:(NSString*)url method:(NSString*)method
                  params:(NSDictionary*)params
                 headers:(NSDictionary<NSString*,NSString*>*)headers
             errorFilter:(Class<JSONResponseErrorFilter>)errorFilter
               dataClass:(Class)dataClass
              parseBlock:(id (^)(id data,id resp,NSError** error))parseBlock;
@end

NS_ASSUME_NONNULL_END
